<layout name="page" />
<block name="content">
	<style>
		.btn-group {
			display: inline-flex;
			margin-left:5px;
			margin-right:5px;
		}
		.btn-group .btn {
			margin: 0px;
		}
	</style>
	{:widget('page_header/simple',array('name'=>$vo['name']))}
	<input type="hidden" id="id" name="id" value="{$vo.id}">
	<div class="operate-panel">
		<a onclick="go_return_url()" class="btn btn-return">返回</a>
		<div class="btn-group">
			<a class="x-click btn" data-val="reply" data-fun="reply">回复</a>
			<button class="btn  dropdown-toggle" data-toggle="dropdown">
				<span class="fa fa-caret-down"></span>
			</button>
			<ul class="dropdown-menu">
				<li>
					<a class="x-click" data-val="reply" data-fun="reply">回复</a>
				</li>
				<li>
					<a class="x-click" data-val="all" data-fun="reply">全部回复</a>
				</li>
				<li>
					<a class="x-click" data-val="forward" data-fun="reply">转发</a>
				</li>
			</ul>
		</div>
		<a onclick="del()"class="x-click btn btn_del" data-fun="del">删除</a>
		<div class="btn-group">
			<a class=" btn  dropdown-toggle" data-toggle="dropdown" href="#"> 标记为 <span class="fa fa-caret-down"></span> </a>
			<ul class="dropdown-menu">
				<li>
					<a class="x-click" data-val="readed" data-fun="mark">已读</a>
				</li>
				<li>
					<a class="x-click" data-val="unread" data-fun="mark">未读</a>
				</li>
			</ul>
		</div>
		<div class="btn-group" id="move_to">
			<a class="btn  dropdown-toggle" data-toggle="dropdown" href="#"> 转移到 <span class="fa fa-caret-down"></span> </a>
			<ul class="dropdown-menu">
				{$folder_list}
			</ul>
		</div>
		<a  onclick="winprint()" class="btn  hidden-xs">打印</a>

		<div class="split"></div>
		<div class="btn-group">
			{$next_link}
		</div>
	</div>

	<div class="frame">
		<div class="frame">
			<div class="box col-12">
				<div class="layui-form-item ">
					<label class="input-label" >发件人：</label>
					<p class="input-block input-static">
						{$vo.from|show_contact}
					</p>
				</div>
			</div>
			<div class="box col-12">
				
					<label class="input-label" >时间：</label>
					<p class="input-block input-static">
						{$vo.create_time|to_date='Y年m月d日 H:i'}
					</p>
				</div>
			</div>
			<div class="box col-12">
				
					<label class="input-label" >收件人：</label>
					<p class="input-static">
						{$vo.to|show_contact}
					</p>
				</div>
			</div>
			<div class="box col-12">
				
					<label class="input-label" >抄送：</label>
					<p class="input-static">
						{$vo.cc|show_contact}
					</p>
				</div>
			</div>
			<div class="box col-12">
				
					<div class="content-wrap" >
						{$vo.content}
					</div>
				</div>
			</div>
			<gt name="vo.add_file|strlen" value="2">
				<div class="box col-12">
					<div class="row layui-form">
						
							<label class="input-label" for="name">附件：</label>
							
								{:widget('file_upload/view',array('add_file'=>$vo['add_file']))}
							</div>
						</div>
					</div>
				</div>
			</gt>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use('global', function() {
			var $ = layui.jquery;

			var active = {
				del : function() {
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							send_ajax("{:url('mark','action=del')}", 'id=' + $("#id").val(), function(data) {
								if (data.status) {
									layer.msg(data.info, function() {
										window.open($("#next_link").attr("href"), '_self');
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},

				mark_spam : function() {
					send_ajax("{:url('mark','action=spam')}", 'mail_id=' + $("#id").val(), function(data) {
						if (data.status) {
							layer.msg(data.info);
						}
					});
				},

				del_forever : function() {
					send_ajax("{:url('mark','action=del_forever')}", 'mail_id=' + $("#id").val(), function(data) {
						if (data.status) {
							layer.msg(data.info);
						}
					});
				},

				forword : function() {
					if ($("input[name='mail_id']:checkbox:checked").length == 1) {
						window.open(fix_url("{:url('reply')}?id=" + $("input[name='mail_id']:checkbox:checked:first").val()) + "&type=forward", "_self");
					} else {
						layer.msg("请选择一封要转发的邮件");
						return false;
					};
				},

				mark : function() {
					var val = $(this).data('val');

					if (val == "readed") {
						send_ajax("{:url('mark','action=readed')}", '&id=' + $("#id").val(), function(data) {
							if (data.status) {
								layer.msg(data.info, function() {
									location.reload(true);
								});
							}
						});
					} else {
						send_ajax("{:url('mark','action=unread')}", '&id=' + $("#id").val(), function(data) {
							if (data.status) {
								layer.msg(data.info, function() {
									location.reload(true);
								});
							}
						});
					}
				},

				reply : function() {
					var type = $(this).data("val");

					if (type == "reply") {
						setTimeout(function() {
							window.location.href = fix_url("{:url('reply','id='.$vo['id'])}?type=" + type);
						}, 300);
					} else {
						window.location.href = fix_url("{:url('reply','id='.$vo['id'])}?type=" + type);
					}
				},
			};

			function move_to(val) {
				send_ajax("{:url('mark','action=move_to')}", 'val=' + val + '&id=' + $("#id").val(), function(data) {
					if (data.status) {
						layer.msg(data.info);
					}
				});
			};

			$('.x-click').on('click', function() {
				var type = $(this).data('fun');
				active[type] ? active[type].call(this) : layer.msg("未定义操作");
			});

			$(document).ready(function() {
				$("#move_to li").click(function() {
					move_to($(this).attr("id"));
				});
			});
		});
	</script>
</block>